#include <REGX52.H>
#include "Delay.h"
#include "LCD1602.h"
#include "MatrixKey.h"


unsigned char KeyNum,count=0; 
unsigned int password=0;


void main()
{
	LCD_Init();
	LCD_ShowString(1,1,"Password:");
	while(1)
	{		
		KeyNum=MatrixKey();
		if(KeyNum)
		{
			if(KeyNum<=10)
			{
				if(count<4)
				{
					password*=10;
					password+=KeyNum;
					count++;
				}
				LCD_ShowNum(2,1,password,4);
			}
			if(KeyNum==11)
			{
				if(password==1234)
				{
					LCD_ShowString(1,14,"OK ");
				}
				else
				{
					LCD_ShowString(1,14,"ERR");
				}
				password=0;
				count=0;
				LCD_ShowNum(2,1,password,4);
			}
			if(KeyNum==12)
			{
				password=0;
				count=0;
				LCD_ShowNum(2,1,password,4);
			}
		}
	}
}